
#include<bits/stdc++.h>
using namespace  std;
int num[100000003];

int main()
{
    long long  n = 0, x = 0;
    cin >> n >> x;
    for(long long i = 1;i <= n;i++)
    {
        cin >> num[i];
    }
    long long  eat = 0,ans = 0;
    for(long long  i = 1;i <= n;i++)
    {
        if(num[i] + num[i + 1] >= x )
        {
            eat += num[i + 1] - x + num[i];
            if(num[i] >= x)
                num[i + 1] = 0;
            else
                num[i + 1] = x - num[i];

        }
    }
    cout << eat;
    return 0;
}